// pages/payment/bodou/bodouDetail/bodouDetail.js
const app = getApp();
const time = require('../../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
  },
  //加载
  load() {
    // console.log("加载")
    let that = this;
    let page = this.data.page;
    page = page + 1;
    that.setData({
      page: page
    })
    this.list();
    console.log("update")
  },
  // 加载
  list: function(e) {
    let that = this;
    let page = this.data.page
    that.get_push(page);
    wx.showLoading({
      icon: 'none',
    })
  },
  //获取推送列表
  get_push(page) {
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/invitation/mybd/bills',
      data: {
        token: app.globalData.token,
        page: page,
      },
      method: 'POST',
      success: function(e) {
        console.log(e)
        //普通情况
        if (e.data.data.current_page > e.data.data.total_page) {
          // console.log("到底了");
          wx.showToast({
            title: '到底啦~',
            icon: 'none',
          })
        } else {
          // console.log("没到底");          
          if (that.data.page == "1") {
            let detail_old = e.data.data.bills;
            detail_old.forEach(function(value, index) {
              value.create_time = time.formatTimeTwo(value.create_time, 'M-D h:m');
            })
            that.setData({
              detail: detail_old,

            })
          } else {
            // console.log("不不不不不");
            let detail = that.data.detail;
            let detail_old = e.data.data.bills;
            detail_old.forEach(function(value, index) {
              value.create_time = time.formatTimeTwo(value.create_time, 'M-D h:m');
            })
            detail.push(...detail_old)
            // console.log(recruit_info);
            that.setData({
              detail: detail,
            })
          }
        }
        // console.log('page+' + that.data.page)
        wx.hideLoading();
      },
    })
  },
  //明细
  getBuylist() {
    const that = this;
    let page = this.data.page;
    wx.request({
      url: app.globalData.url + 'api/invitation/mybd/bills',
      data: {
        token: app.globalData.token,
        page: page,
      },
      method: 'POST',
      success: function(e) {
        console.log(e)
        let detail = e.data.data.bills;
        console.log(detail)
        detail.forEach(function(value, index) {
          value.create_time = time.formatTimeTwo(value.create_time, 'Y.M.D h:m');
        })
        that.setData({
          detail: detail,
        })
      },
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.get_push(1);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})